﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using InfoJetSoft.Service;
using Microsoft.SharePoint;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint.Utilities;
using System.Text;
using System.Web;
using ServBus.ListForm2010.Utility;
using ServBus.ListForm2010.Extension;
using FluentRibbon.Libraries;
using FluentRibbon.Definitions;
using FluentRibbon;
using Microsoft.SharePoint.WebControls;
using FluentRibbon.Definitions.Controls;
using ServBus.ListForm2010.Resources;

namespace ServBus.ListForm2010.Layouts.InfoBus2010
{
    public partial class ListFormInner1 : LayoutsPageBase
    {
        #region Parameters

        public static bool urlMode = true;
        public static string webpartMode = string.Empty;//"NEW";
        public static string siteName = "";//"http://win-3ststb2hjp7";
        public static string webName = "";//"Test";
        public static string listId = "";//"test";
        public static string ctypeId = "";
        public static string itemId = "";//string.Empty;
        public static string infojet_ServiceAction = "/_layouts/infobus2010/xdoc.aspx";


        XmlNamespaceManager xNameSpace;

        static string pulishUrl = string.Empty;
        #endregion

        #region Page Method
        protected void Page_Load(object sender, EventArgs e)
        {

            try
            {
                InfoJetService.ServiceAction = infojet_ServiceAction;
                InfoJetSoft.Service.Util.ConfigUtil.SetEnableRichText(true);
                InfoJetSoft.Service.Util.ConfigUtil.EditRichTextOnFocus = true;
                InfoJetSoft.Service.Util.ConfigUtil.SetEnableFormFieldsCache(true);
                InfoJetSoft.Service.Util.ConfigUtil.SetEnablePlaceholderUI(true);

                webpartMode = Page.Request["wpMode"].ToUpper();
                listId = Page.Request["listId"];
                ctypeId = Page.Request["ctype"];
                siteName = SPContext.Current.Site.Url;

                webName = SPContext.Current.Web.Name;
                if (!Page.IsPostBack)
                {
                    switch (webpartMode)
                    {
                        case "NEW":
                            GenerateNewForm();
                            break;
                        case "DISP":
                            itemId = Page.Request["itemId"];
                            GenerateDisplayForm();
                            break;
                        case "EDIT":
                            itemId = Page.Request["itemId"];
                            GenerateEditForm();
                            break;
                        default:
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                exView.Visible = true;
                exView.Text = ex.ToString();
            }
        }


        protected void DeleteBtn_Click(object sender, EventArgs e)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(siteName))
                {
                    using (SPWeb _web = _site.OpenWeb(webName))
                    {
                        _web.AllowUnsafeUpdates = true;
                        SPList _list = _web.Lists[new Guid(listId)];
                        int _itemId = Convert.ToInt32(itemId);
                        SPListItem _item = _list.GetItemById(_itemId);
                        _item.Recycle();
                    }
                }
            });
            Response.Write("<script type='text/javascript'>parent.window.frameElement.commitPopup('some value')</script>");
        }

        protected void SaveBtn_Click(object sender, EventArgs e)
        {
            try
            {

                InfoJetContext ijCtx = new InfoJetContext();
                ijCtx.InlineFileStorage = new InlineFileStorage();
                InfoJetForm savedForm = InfoJetService.ReloadForm(Context, ijCtx);
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(savedForm.Xml);

                xNameSpace = new XmlNamespaceManager(new NameTable());
                xNameSpace.AddNamespace("my", xDoc.NamespaceURI);
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite _site = new SPSite(siteName))
                    {
                        using (SPWeb _web = _site.OpenWeb(webName))
                        {
                            _web.AllowUnsafeUpdates = true;
                            SPList _list = _web.Lists[new Guid(listId)];
                            int _itemId = 0;
                            if (webpartMode.Equals("NEW"))
                            {
                                SPListItem newItem = _list.Items.Add();
                                newItem.Update();
                                _itemId = newItem.ID;
                            }
                            else if (webpartMode.Equals("EDIT"))
                            {
                                _itemId = Convert.ToInt32(itemId);
                            }
                            SPListItem _item = _list.GetItemById(_itemId);
                            foreach (XmlNode xNode in xDoc.ChildNodes)
                            {
                                SaveListFieldsValue(xNode, _list, _item);
                            }
                            _item.Update();
                        }
                    }
                });
                //Response.Write("<script type='text/javascript'>window.close()</script>");
                Response.Write("<script type='text/javascript'>parent.window.frameElement.commitPopup('some value')</script>");
            }
            catch (Exception ex)
            {
                exView.Visible = true;
                exView.Text = ex.ToString();
            }
        }
        #endregion

        #region Private Method

        private void GenerateDisplayForm()
        {
            
            string xmlTemplate = GetXMLTemplate().Xml;
            if (xmlTemplate != string.Empty)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(xmlTemplate);

                xNameSpace = new XmlNamespaceManager(new NameTable());
                xNameSpace.AddNamespace("my", xDoc.NamespaceURI);

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite _site = new SPSite(siteName))
                    {
                        using (SPWeb _web = _site.OpenWeb(webName))
                        {
                            SPList _list = _web.Lists[new Guid(listId)];
                            int _itemId = Convert.ToInt32(itemId);
                            SPListItem _item = _list.GetItemById(_itemId);
                            foreach (XmlNode xNode in xDoc.ChildNodes)
                            {
                                SetListFieldsValue(xNode, _list, _item);
                            }

                            InfoJetContext ijCtx = new InfoJetContext();
                            ijCtx.InlineFileStorage = new InlineFileStorage();
                            ijCtx.ExportFileStorage = new ExportFileStorage();
                            RelativeUrlResolver resolver = new RelativeUrlResolver(_xsnLocation);
                            ijCtx.RelativeUrlResolver = resolver;
                            ijCtx.IsReadonly = true;
                            InfoJetForm editForm = InfoJetService.BuildFormByXML(Context, ijCtx, _xsnLocation, xDoc.OuterXml);
                            //xDocView.Text = editForm.Xhtml;
                            //formView.XmlForm
                        }
                    }
                });
            }
        }

        private void GenerateNewForm()
        {
            //#region add ribbon buttons
            //var tabDefinition = new TabDefinition()
            //{

            //    Id = "EditRibbon",
            //    Title = "Edit",
            //    Groups = new GroupDefinition[]
            //    {
            //        new GroupDefinition()
            //        {
            //            Id = "commitGroup",
            //            //Title = Resource.GetString("RibbonGroup_Submit"),
            //            Title = "Commit",
            //            Template = GroupTemplateLibrary.SimpleTemplate,
            //            Controls = new ControlDefinition[]
            //            {
            //                new ButtonDefinition()
            //                {
            //                    Id = "SaveButton",
            //                    //Title = Resource.GetString("Btn_Save"),
            //                    Title = "Save",
            //                    CommandJavaScript = "saveFormPart();",
            //                    //Image = ImageLibrary.GetStandardImage(8, 13,_currentlcid),
            //                    Image = new ImageDefinition()
            //                    { 
            //                        Url32 = "/_layouts/InfoBus2010/Images/Save32.png"
            //                    }
            //                },
            //                new ButtonDefinition()
            //                {
            //                    Id = "CloseButton",
            //                    //Title = Resource.GetString("Btn_Close"),
            //                    Title ="Close",
            //                    CommandJavaScript = "window.frameElement.commitPopup('some value');",
            //                    //Image = ImageLibrary.GetStandardImage(9, 14,_currentlcid)
            //                    Image = new ImageDefinition()
            //                    { 
            //                        Url32 = "/_layouts/InfoBus2010/Images/Close32.png"
            //                    }
            //                }                                        
            //            }
            //        }

            //    }
            //};



            //RibbonController.Current.AddRibbonTabToPage(tabDefinition, this.Page, true);

            //#endregion
            //Create the web form of the template xml document with the publish url.
            InfoJetForm newForm = GetXMLTemplate();
            if (newForm != null)
            {
                //this.xDocView.Text = newForm.Xhtml;
            }
        }

        private void GenerateEditForm()
        {
            #region add ribbon buttons
            //var tabDefinition = new TabDefinition()
            //{

            //    Id = "EditRibbon",
            //    Title = "Edit",
            //    Groups = new GroupDefinition[]
            //    {
            //        new GroupDefinition()
            //        {
            //            Id = "commitGroup",
            //            //Title = Resource.GetString("RibbonGroup_Submit"),
            //            Title = "Commit",
            //            Template = GroupTemplateLibrary.SimpleTemplate,
            //            Controls = new ControlDefinition[]
            //            {
            //                new ButtonDefinition()
            //                {
            //                    Id = "SaveButton",
            //                    //Title = Resource.GetString("Btn_Save"),
            //                    Title = "Save",
            //                    CommandJavaScript = "saveFormPart();",
            //                    //Image = ImageLibrary.GetStandardImage(8, 13,_currentlcid),
            //                    Image = new ImageDefinition()
            //                    { 
            //                        Url32 = "/_layouts/InfoBus2010/Images/Save32.png"
            //                    }
            //                },
            //                new ButtonDefinition()
            //                {
            //                    Id = "CloseButton",
            //                    //Title = Resource.GetString("Btn_Close"),
            //                    Title ="Close",
            //                    CommandJavaScript = "window.frameElement.commitPopup('some value');",
            //                    //Image = ImageLibrary.GetStandardImage(9, 14,_currentlcid)
            //                    Image = new ImageDefinition()
            //                    { 
            //                        Url32 = "/_layouts/InfoBus2010/Images/Close32.png"
            //                    }
            //                }                                        
            //            }
            //        },
            //        new GroupDefinition()
            //        {
            //            Id = "actionsGroup",
            //            //Title = Resource.GetString("RibbonGroup_Submit"),
            //            Title = "Actions",
            //            Template = GroupTemplateLibrary.SimpleTemplate,
            //            Controls = new ControlDefinition[]
            //            {
            //                new ButtonDefinition()
            //                {
            //                    Id = "DeleteButton",
            //                    //Title = Resource.GetString("Btn_Save"),
            //                    Title = "Delete Item",
            //                    CommandJavaScript = "deleteFormPart();",
            //                    //Image = ImageLibrary.GetStandardImage(8, 13,_currentlcid),
            //                    Image = new ImageDefinition()
            //                    { 
            //                        Url32 = "/_layouts/InfoBus2010/Images/Delete32.png"
            //                    }
            //                }                                 
            //            }
            //        }
            //    }
            //};



            //RibbonController.Current.AddRibbonTabToPage(tabDefinition, this.Page, true);

            #endregion
            string xmlTemplate = GetXMLTemplate().Xml;
            if (xmlTemplate != string.Empty)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(xmlTemplate);

                xNameSpace = new XmlNamespaceManager(new NameTable());
                xNameSpace.AddNamespace("my", xDoc.NamespaceURI);

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite _site = new SPSite(siteName))
                    {
                        using (SPWeb _web = _site.OpenWeb(webName))
                        {
                            SPList _list = _web.Lists[new Guid(listId)];
                            int _itemId = Convert.ToInt32(itemId);
                            SPListItem _item = _list.GetItemById(_itemId);
                            foreach (XmlNode xNode in xDoc.ChildNodes)
                            {
                                SetListFieldsValue(xNode, _list, _item);
                            }
                            InfoJetContext ijCtx = new InfoJetContext();
                            ijCtx.InlineFileStorage = new InlineFileStorage();
                            ijCtx.ExportFileStorage = new ExportFileStorage();
                            RelativeUrlResolver resolver = new RelativeUrlResolver(_xsnLocation);
                            ijCtx.RelativeUrlResolver = resolver;
                            InfoJetForm editForm = InfoJetService.BuildFormByXML(Context, ijCtx, _xsnLocation, xDoc.OuterXml);
                            //xDocView.Text = editForm.Xhtml;
                        }
                    }
                });
            }
        }

        private string _xsnLocation = "";

        private bool RegisterXSNTemplate()
        {
            Guid xsnId;

            byte[] xsnContent = null;

            bool succeed = false;
            InfoJetService.License("SHAREPOINT+JWbHbmhKDvaqyuWdEGHV8");

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(siteName))
                {
                    using (SPWeb _web = _site.OpenWeb(webName))
                    {
                        SPList _list = _web.Lists[new Guid(listId)];
                        SPContentTypeId _ctypeId = new SPContentTypeId(ctypeId.ToLower());
                        SPContentType _cType = _list.ContentTypes[_ctypeId];
                        // _cType.ResourceFolder.Url;
                        //string destFileUrl = _web.Url + "/" + _cType.ResourceFolder.Url + "/template.xsn";
                        _xsnLocation = _web.Url + "/" + _cType.ResourceFolder.Url + "/template.xsn";

                        SPFile file = _web.GetFile(_xsnLocation);
                        xsnContent = file.OpenBinary();
                        xsnId = file.UniqueId;


                        if (xsnContent == null)
                        {
                            succeed = false;
                        }
                        else
                        {
                            // Register
                            string md5 = CryptoUtility.ComputeMD5(xsnContent);
                            if (InfoJetService.GetMD5(_xsnLocation) == md5)
                            {
                                succeed = true;
                            }
                            else
                            {
                                InfoJetContext ijCtx = new InfoJetContext();
                                ijCtx.Variables.Add("InfoBus_XsnId", xsnId.ToString());
                                ijCtx.ResourceFileStorage = new ResourceFileStorage(_web);
                                ijCtx.InlineFileStorage = new InlineFileStorage();
                                if (!InfoJetService.RegisterWithMD5(Context, ijCtx, _xsnLocation, xsnContent, "/_layouts/infobus2010/", md5))
                                {
                                    succeed = false;
                                }
                                else
                                {
                                    succeed = true;
                                }
                            }
                        }
                    }
                }
            });
            return succeed;
        }

        private InfoJetForm GetXMLTemplate()
        {
            string xmlTemplate = string.Empty;
            if (RegisterXSNTemplate())
            {

                InfoJetContext ijCtx = new InfoJetContext();
                ijCtx.InlineFileStorage = new InlineFileStorage();
                ijCtx.ExportFileStorage = new ExportFileStorage();
                RelativeUrlResolver resolver = new RelativeUrlResolver(_xsnLocation);
                ijCtx.RelativeUrlResolver = resolver;
                InfoJetForm newForm = InfoJetService.BuildFormByTemplate(Context, _xsnLocation, ijCtx);
                return newForm;
            }
            else
            {
                return null;
            }
        }

        private void SetListFieldsValue(XmlNode xNode, SPList p_list, SPListItem p_item)
        {
            if (xNode.HasChildNodes)
            {
                foreach (XmlNode cXNode in xNode.ChildNodes)
                {
                    SetListFieldsValue(cXNode, p_list, p_item);
                }
            }
            SetValue(xNode.CreateNavigator(), p_list, p_item);
        }

        private void SetValue(XPathNavigator p_xPathNav, SPList p_list, SPListItem p_item)
        {
            string m_field_internal_name = string.Empty;
            string m_field_value = string.Empty;

            if (p_xPathNav != null)
            {
                string localName = Convert.ToString(p_xPathNav.LocalName);

                //begin looping through the nodes
                if (localName != null)
                {
                    #region Set Value

                    m_field_internal_name = p_xPathNav.LocalName;
                    if (p_list.Fields.ContainsField(m_field_internal_name))
                    {
                        SPField m_field = p_list.Fields.GetField(m_field_internal_name);

                        m_field_value = GetFormValueFromField(m_field, p_item);

                        if (string.IsNullOrEmpty(m_field_value))
                        {
                            return;
                        }

                        //根据不同的Field类型，表单对应不同的数据类型，这里需要判断
                        switch (m_field.Type)
                        {
                            case SPFieldType.Number:
                                DeleteNil(p_xPathNav);
                                p_xPathNav.SetValue(m_field_value);
                                break;

                            case SPFieldType.DateTime:
                                DeleteNil(p_xPathNav);
                                p_xPathNav.SetValue(m_field_value);
                                break;

                            case SPFieldType.User:
                                if (p_xPathNav.InnerXml == "")
                                {
                                    return;
                                }
                                InsertToUserType(m_field_value, p_xPathNav);
                                break;

                            case SPFieldType.MultiChoice:
                                InsertIntoCheckBoxType(m_field_value, p_xPathNav);
                                break;

                            default:
                                p_xPathNav.SetValue(m_field_value);
                                break;
                        }
                    }
                    #endregion
                }
            }
        }

        private void SaveListFieldsValue(XmlNode xNode, SPList p_list, SPListItem p_item)
        {
            if (xNode.HasChildNodes)
            {
                foreach (XmlNode cXNode in xNode.ChildNodes)
                {
                    SaveListFieldsValue(cXNode, p_list, p_item);
                }
            }
            SaveValue(xNode.CreateNavigator(), p_list, p_item);
        }

        private void SaveValue(XPathNavigator p_xPathNav, SPList p_list, SPListItem p_item)
        {
            string m_field_internal_name = string.Empty;

            if (p_xPathNav != null)
            {
                string localName = Convert.ToString(p_xPathNav.LocalName);

                //begin looping through the nodes
                if (localName != null)
                {
                    if (!string.IsNullOrEmpty(p_xPathNav.Value))
                    {
                        m_field_internal_name = p_xPathNav.LocalName;
                        if (p_list.Fields.ContainsField(m_field_internal_name))
                        {
                            SPField m_field = p_list.Fields.GetField(m_field_internal_name);
                            SPFieldType m_field_type = m_field.Type;
                            //单独处理CheckBox
                            if (!m_field.ReadOnlyField)
                            {
                                if (m_field_type.Equals(SPFieldType.MultiChoice))
                                {
                                    XPathNodeIterator itr = p_xPathNav.Select("Value");

                                    SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue();

                                    while (itr.MoveNext())
                                    {
                                        values.Add(itr.Current.Value);
                                    }
                                    p_item[m_field.Id] = values;
                                    p_item.Update();
                                }
                                else
                                {
                                    object m_field_value = GetFieldValueByType(m_field_type, p_xPathNav.Value);
                                    p_item[m_field.Id] = m_field_value;
                                    p_item.Update();
                                }
                            }
                        }
                    }
                }
            }
        }

        //通过SPField的Type，返回不同的对象，给Item的属性赋值。
        public object GetFieldValueByType(SPFieldType p_field_type, string p_str_value)
        {
            object m_field_value = null;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(siteName))
                {
                    using (SPWeb _web = _site.OpenWeb(webName))
                    {
                        switch (p_field_type)
                        {
                            case SPFieldType.Text:
                                m_field_value = p_str_value;
                                break;
                            case SPFieldType.User:
                                try
                                {
                                    SPUser m_user = _web.EnsureUser(p_str_value);
                                    m_field_value = m_user;
                                }
                                catch
                                {
                                    m_field_value = _web.CurrentUser;
                                    //输出错误信息，用户不存在之类的。
                                }
                                break;
                            case SPFieldType.Integer:
                                int m_integer = int.Parse(p_str_value);
                                m_field_value = m_integer;
                                break;
                            case SPFieldType.Number:
                                double m_number = double.Parse(p_str_value);
                                m_field_value = m_number;
                                break;
                            case SPFieldType.Lookup:
                                SPFieldLookupValue m_lookup_value = new SPFieldLookupValue(p_str_value);
                                m_field_value = m_lookup_value;
                                break;
                            default:
                                m_field_value = p_str_value;
                                break;
                        }
                    }
                }
            });

            return m_field_value;
        }

        /// <summary>
        /// 从列表的Field中获取值填充到InfoPath节点中
        /// </summary>
        /// <param name="p_field"></param>
        /// <param name="p_item"></param>
        /// <returns></returns>
        private string GetFormValueFromField(SPField p_field, SPListItem p_item)
        {

            string m_str_value = string.Empty;
            try
            {

                if (p_item[p_field.Id] == null)
                {
                    return m_str_value;
                }
            }
            catch (Exception ex)
            {
                return m_str_value;
            }


            switch (p_field.Type)
            {
                case SPFieldType.Lookup:
                    string m_lookup_value = p_item[p_field.Id].ToString();

                    int t_index = m_lookup_value.IndexOf("#");
                    m_str_value = m_lookup_value.Substring(t_index + 1);
                    //m_str_value = m_lookup_value;                   //读取数据时出错。TO DO...目前先临时改回来
                    break;

                case SPFieldType.DateTime:
                    DateTime m_time = (DateTime)p_item[p_field.Id];
                    m_str_value = XmlConvert.ToString(m_time);
                    break;

                case SPFieldType.Note:
                    m_str_value = GetMulitTextString(Convert.ToString(p_item[p_field.Id]));
                    break;

                case SPFieldType.URL:
                    SPFieldUrlValue urlValue = new SPFieldUrlValue(Convert.ToString(p_item[p_field.Id]));
                    m_str_value = urlValue.Url;
                    break;

                case SPFieldType.Boolean:
                    bool booleanField = Convert.ToBoolean(p_item[p_field.Id]);
                    if (booleanField)
                    {
                        m_str_value = "true";
                    }
                    else
                    {
                        m_str_value = "false";
                    }
                    break;

                default:
                    m_str_value = Convert.ToString(p_item[p_field.Id]);
                    break;
            }
            return m_str_value;
        }

        /// <summary>
        /// 架构验证发现无数据类型错误的解决方案，目前只用于数字类型
        /// </summary>
        /// <param name="node">当前节点</param>
        private void DeleteNil(XPathNavigator node)
        {
            if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
            {
                node.DeleteSelf();
            }
        }

        /// <summary>
        /// 插入用户信息到pc:Person类型的节点中
        /// </summary>
        /// <param name="fieldValue"></param>
        /// <param name="xPathNav"></param>
        private void InsertToUserType(string fieldValue, XPathNavigator xPathNav)
        {
            SPFieldUserValue userValue = new SPFieldUserValue();

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(siteName))
                {
                    using (SPWeb _web = _site.OpenWeb(webName))
                    {
                        userValue = new SPFieldUserValue(_web, fieldValue);
                    }
                }
            });

            XPathNavigator nav = xPathNav.SelectSingleNode("pc:Person", xNameSpace);
            if (nav.MoveToFirstChild())
            {
                switch (nav.LocalName)
                {
                    case "DisplayName":
                        nav.SetValue(userValue.User.Name);
                        break;

                    case "AccountId":
                        nav.SetValue(userValue.User.LoginName);
                        break;

                    case "AccountType":
                        nav.SetValue("User");
                        break;

                    default:
                        break;
                }

                while (nav.MoveToNext())
                {
                    switch (nav.LocalName)
                    {
                        case "DisplayName":
                            nav.SetValue(userValue.User.Name);
                            break;

                        case "AccountId":
                            nav.SetValue(userValue.User.LoginName);
                            break;

                        case "AccountType":
                            nav.SetValue("User");
                            break;

                        default:
                            break;
                    }
                }
            }

        }

        private void InsertIntoCheckBoxType(string fieldValue, XPathNavigator xPathNav)
        {
            SPFieldMultiChoiceValue choiceValue = new SPFieldMultiChoiceValue(fieldValue);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < choiceValue.Count; i++)
            {
                sb.Append("<Value>").Append(choiceValue[i]).Append("</Value>");
            }
            xPathNav.InnerXml = sb.ToString();
        }

        private string GetMulitTextString(string p_field_string)
        {
            string m_comment = string.Empty;
            try
            {
                XmlDocument m_doc = new XmlDocument();
                m_doc.LoadXml(p_field_string);

                XmlElement m_xe = m_doc.DocumentElement;
                if (!string.IsNullOrEmpty(m_xe.InnerText))
                {
                    m_comment = m_xe.InnerText;
                }

            }
            catch { }

            return m_comment;
        }


        #endregion
    }
}
